<?php
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Cache-Control: no-cache");
header("Pragma: no-cache");

require_once ('../../config/path_config.php');
require_once (ROOTDIR."config/sys_config.php");

/*
function getNewMailCnt()
{
    $userId = $_SESSION['user_id'];
    $sql="SELECT count(1) FROM `mail` WHERE new_mail=1 AND `to_user`=?";
    $result=pdo_query($sql, $userId);
    if( !$result ) {
        return 0;
    }
    $row=$result[0];
    return intval($row[0]);
}
*/

$profile='';
$mailCnt = 0;
if ( isset($_SESSION['user_id']) )
{
    $sid=$_SESSION['user_id'];

    //$mailCnt = getNewMailCnt();
    $mailHtml = "";
    if ( $mailCnt > 0 ) {
        $mailHtml = "<font color='#ff4500'>($mailCnt)</font>";
    }

    // 可再此添加邮件查看功能,路径跳转问题，全部修改为根目录
    $profile.= "&nbsp;<li><a href=/status.php?user_id=$sid><span>我的提交</span></a></li>";
    //$profile.= "&nbsp;<li><a href='../../status.php?user_id=$sid'><span>我的消息$mailHtml</span></a></li>";
    $profile.= "&nbsp;<li><a href=/front/view/stash_code_list.php>源码暂存</a></li>";
    $profile.= "&nbsp;<li><a href=/modifypasswdpage.php>修改密码</a></li>";
    $profile.= "&nbsp;<li><a href=/logout.php>注销</a></li>&nbsp;";

    $hasAdminAuth = false;
    $roleArray = array();
    array_push($roleArray, 'administrator', 'teacher');
    array_push($roleArray, 'jgadmin', 'xxadmin');
    array_push($roleArray, 'problem_editor', 'problem_checker');
    foreach ( $roleArray as $role) {
        if ( isset($_SESSION[$role]) ) {
            $hasAdminAuth = true;
            break;
        }
    }

    if ( $hasAdminAuth )
    {
        $profile.= "<li><a href=/admin/>管理</a></li>&nbsp;";
    }
}
else {
    $profile.= "<li><a href=/loginpage.php>登录</a></li>&nbsp;";
    if ( isset(SysConfig::$ALLOW_REGISTER) && SysConfig::$ALLOW_REGISTER ) {
        $profile.= "<li><a href=/front/view/register_view.php>注册</a></li>&nbsp;";
    }
}

$htmlData = '登录';
if ( isset($sid) ) {
    $htmlData = "<span>$sid$mailHtml</span>";
}

?>
document.write("<?php echo ( $profile);?>");
document.getElementById("profile").innerHTML="<?php echo $htmlData ?>";

